package kr.hkit.powerjava.chapter25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class URLHostTest {
   public static void main(String[] args) {
//      http://www.hkit.kr/SUB/?ctId=22
      
      try {
         URL url = new URL("http://www.hkit.kr/SUB/");
         URLConnection connection = url.openConnection();
         connection.setDoOutput(true);
         
         OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
         out.write("ctId"+22);
         out.close();
         
         BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
         String line;
         while((line = in.readLine()) != null) {
            System.out.println(line);
         }
         in.close();
      } catch (MalformedURLException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
}
